<?php
    include('inc/db.php');
    include('template/_header.php');
?>
<div id="contact">
<?php
$rows_per_page = 10;
$page = $_GET['page'];
$offset = (!empty($page)) ? $page : $page = 1;
$self = $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'];
$self = str_replace("page={$offset}", "", $self);

$offset = ($page) ? ($page - 1) * $rows_per_page : 0;
$query = "SELECT * "."FROM post "."ORDER BY id "." DESC LIMIT {$offset},{$rows_per_page}";
$result = mysql_query($query);
$ltq = mysql_query("SELECT * FROM post");
$listings_total = mysql_num_rows($ltq);
$NumPgs = ceil($listings_total / $rows_per_page);
    while($row = mysql_fetch_array($result)){
        echo '<div class="post-time">'.'发表于'.date(' H:i M jS D Y',$row['post_time']).'</div>';
        echo '<div class="post">'.'<h3><a href="riji.php?id='.$row['id'].'">'.$row['title'].'</a>'.'</h3>';
        echo '<div class="post-content">'.mb_substr($row['content'],0,200,'UTF-8').'...'.'</div>'.'</div>';
    }
?>

<span style="float:right">
    <?=$prev = ($NumPgs > 0 && $page!=1) ? "<a href=\"{$self}page=".($page-1)."\">&lt;&lt;Prev</a>&nbsp;&nbsp;":
    "&lt;&lt;Prev&nbsp;&nbsp;"; ?>
    [Page <?php echo $page; ?>]
    <?=$next = ($page < $NumPgs) ? "<a href=\"{$self}page=".($page+1)."\">&nbsp;&nbsp;Next&gt;&gt;</a>":
    "&nbsp;&nbsp;Next&gt;&gt;";?>&nbsp;
</span>
<b><?=$listings_total?> 篇言论&nbsp; 第 <?=$offset+1?> 到 <?=$offset+$rows_per_page?> 篇 </b>
</div>
<?php
    include('template/_footer.php');
?>
